package com.opoc.service.Impl;

import com.opoc.mapper.AdminMapper;
import com.opoc.pojo.Admin;
import com.opoc.service.AdminService;
import com.opoc.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class AdminServiceImpl implements AdminService {
  @Autowired
  AdminMapper adminMapper;

  /**
   *
   * @param account
   * @param password
   * @return
   * @描述 登录 返回token name id
   */
  @Override
  public Map<String, String> login(String account, String password) {
    Admin admin = adminMapper.login(account, password);
    Map<String, String> data = new HashMap<>();
    if (admin != null) {
      Map<String, Object> claims = new HashMap<>();
      claims.put("account",account);
      claims.put("admin_id", admin.getId());
      String Token = JwtUtils.getToken(claims);
      data.put("token", Token);
      data.put("name", admin.getName());
      data.put("admin_id", admin.getId());
    }
//    log.info(data.toString());
    return data;
  }
}
